package homework1_3;

import java.io.IOException;
import java.net.Socket;

/**
 * 客户端实例
 */
public class Client02 {
    public static void main(String[] args) {
        Socket socket = null;
        try {
            socket = new Socket("127.0.0.2",8000);
            System.out.println("连接服务器成功");
            ClientClass c1 = new ClientClass("tt",socket);//创建一个客户端实例
            Thread t1 = c1.send();//获取发送消息线程
            Thread t2 = c1.receive();//获取接收消息线程
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            c1.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            //关闭socket
            if (null!=socket){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }


    }
}

